<template>
  <div>
    <el-breadcrumb separator-class="el-icon-arrow-right" class="top">
      <el-breadcrumb-item :to="{ path: '/home' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item>数据统计</el-breadcrumb-item>
      <el-breadcrumb-item>数据报表</el-breadcrumb-item>
    </el-breadcrumb>
    <el-card class="box-card">
      <div id="myecharts" style="width: 600px; height: 400px"></div>
    </el-card>
  </div>
</template>
<script>
export default {
  name: "reports",
  data() {
    return {
      dataobj: null, 
      options: {
        title: {
          text: "用户来源",
        },
        tooltip: {
          trigger: "axis",
          axisPointer: {
            type: "cross",
            label: {
              backgroundColor: "#E9EEF3",
            },
          },
        },
        grid: {
          left: "3%",
          right: "4%",
          bottom: "3%",
          containLabel: true,
        },
        xAxis: [
          {
            boundaryGap: false,
          },
        ],
        yAxis: [
          {
            type: "value",
          },
        ],
      },
    };
  },
  methods: {
    drawLine() {
      let myChart = this.$echarts.init(document.getElementById("myecharts"));
      this.options = { ...this.options, ...this.dataobj };
      myChart.setOption(this.options);
    },
  },
  async mounted() {
    let rst = await this.$http.get("reports/type/1");
    if (rst.meta.status == 200) {
      this.dataobj = rst.data;
      this.drawLine();
    } else {
      this.$message.error("获取报表数据失败");
    }
  },
}
</script>

<style>
.top {
  margin-bottom: 20px;
}
</style>